<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<div id="app">
    <button @click="showc">显示仓库的内容</button>
    <h1>{{this.$store.state.count}}</h1>
    <button @click="add">加2</button>
</div>

<script src="node_modules/vue/dist/vue.js"></script>
<script src="node_modules/vuex/dist/vuex.js"></script>
<script src="node_modules/axios/dist/axios.js"></script>

<script>
    // console.log(Vuex);
    //创建仓库
    let store = new Vuex.Store({
        state:{
            count:999
        },
        mutations:{
            increate:function(state,c){
                state.count += c;
            }
        },
        //提交异步的操作
        actions:{
            asyncincreate:function(store){
                axios.get("http://linweiqin.cn:8001/statis/admin/2020-10-17/count").then(res => {
                    console.log(res.data.count);
                    store.commit("increate",res.data.count);
                }).catch(err => console.log(err));
            }
        }
    })

    var vm = new Vue({
        el:"#app",
        data:{
            count:0
        },
        store,//
        methods: {
            showc:function(){
                console.log(this.$store);
            },
            add:function(){
                this.$store.dispatch("asyncincreate");
            },
        }
    })
</script>

</body>
</html>